<!DOCTYPE html>
<html>
    
	<head>
		<meta charset="utf-8">
		<title>工单列表</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
        
		 <link rel="import" href="../header.html" id="page1">
	</head>

	<body>

		<style>
			.mui-control-content {
				background-color: white;
				min-height: 215px;
			}
			.mui-control-content .mui-loading {
				margin-top: 50px;
			}
			
			.mui-table-view:before,.mui-table-view:after{
				height: 0px;
			}
			.mui-card{
				margin: 0 5px;
				border-radius: 5px;
			}
			.mui-search{
				margin: 0 5px;
			}
		</style>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">工单列表</h1>
		</header>

		<div id="app" class="mui-content" v-cloak>
			<div style="margin-top: 10px;margin-bottom: 10px;" id="sliderSegmentedControl" class="mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<a class="mui-control-item mui-active" href="javaScript:void(0)" @click="getWarningRecordList('down','0')">
					待处理
				</a>
				<a class="mui-control-item" href="javaScript:void(0)" @click="getWarningRecordList('down','1')">
					进行中
				</a>
				<a class="mui-control-item" href="javaScript:void(0)" @click="getWarningRecordList('down','2')">
					已处理
				</a>
			</div>
			
			<!--下拉刷新容器-->
			<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
				<div class="mui-content-padded">
					<div class="mui-input-row mui-search">
						<input type="search" class="mui-input-clear" placeholder="">
					</div>
				</div>
				<div class="mui-scroll" style="top:90px;">
					<!--数据列表-->
					<ul class="mui-table-view mui-table-view-chevron" style="background-color:#efeff4">
						<li v-for="item in bussmaintaintask" class="" style="padding:5px 10px;">
							<div class="mui-card">
								<!--页眉，放置标题-->
								<div class="mui-card-header" v-if="item.status == '0'">{{item.createTime}}</div>
								<div class="mui-card-header" v-if="item.status == '1'">{{item.receiveTime}}</div>
								<div class="mui-card-header" v-if="item.status == '2'">{{item.finishTime}}</div>
								<!--内容区-->
								<div class="mui-card-content">
									<div class="mui-card-content-inner">
										<div>工单编号:  {{item.businessNum}}</div>
										<div>设备名称:  {{item.equipmentName}}</div>
										<div>紧急度:  {{item.gradeNumName}}</div>
										<div>指派人:  {{item.handlerName}}</div>
										<div>状态:  {{item.statusDesc}} </div>
										<div v-if="item.status == '0'">创建时间:  {{item.createTime}} </div>
										<div v-if="item.status == '1'">指派时间:  {{item.receiveTime}} </div>
										<div v-if="item.status == '2'">完成时间:  {{item.finishTime}} </div>
										<div>描述:  {{item.content}} </div>
										
									</div>
								</div>
								<!--页脚，放置补充信息或支持的操作-->
								<div class="mui-card-footer">
									<button type="button" class="mui-btn mui-btn-primary"  @click="bu1(item.id)"  >详情</button>
									<button type="button" v-if="item.status == '0'" class="mui-btn mui-btn-primary"  @click="update(item.id)"  >修改</button>
									<button type="button" v-if="item.status == '0'" class="mui-btn mui-btn-primary"  @click="receive(item.id)"  >接收</button>
									<button type="button" v-if="item.status == '0'" class="mui-btn mui-btn-primary"  @click="del(item.id)"  >删除</button>
									<button type="button" v-if="item.status == '1'" class="mui-btn mui-btn-primary"  @click="fk(item.id)"  >反馈</button>
								</div>
							</div>
						</li>
					</ul>
					
				</div>
				
			</div>
			
		</div>

		<script src="../../js/mui.picker.js"></script>
		<script src="../../js/mui.poppicker.js"></script>
		<script src="../../js/mui.pullToRefresh.js"></script>
		<script src="../../js/mui.pullToRefresh.material.js"></script>
		<script>
		var vm = new Vue({
			el:"#app",
			data:{
				bussmaintaintask:[],
				currPage:0,
				totalCount:0,
				totalPage:1,
				search:0
			},
			methods:{
				// 获取告警记录信息
				getWarningRecordList(type,search){
					if(search != ''){
						vm.search = search
					}
					
					var vmObj = this;
					mui.getJSON(baseUrl+"/buss/bussmaintaintask/list",{"page":vmObj.currPage,"limit":10,'status': vm.search,},function(r){
						if (r.code == 0) {
							vmObj.totalCount = r.page.totalCount;
							vmObj.totalPage = r.page.totalPage;
							if(type=="down"){// 下拉刷新
								vmObj.bussmaintaintask = r.page.list;
								mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
								if(vmObj.currPage<vmObj.totalPage){
									mui('#pullrefresh').pullRefresh().refresh(true);
								}
								mui.toast("刷新成功");
							}else{// 下拉加载
								vmObj.bussmaintaintask = vmObj.bussmaintaintask.concat(r.page.list);
								mui('#pullrefresh').pullRefresh().endPullupToRefresh(vmObj.currPage>=vmObj.totalPage); //参数为true代表没有更多数据了。
								mui.toast("加载了"+r.page.list.length+"条告警记录");
							}
							
							
						}else{
							mui.toast(r.msg);
						}
					});
				},
				/**
				 * 上拉加载具体业务实现
				 */
				pullupRefresh() {
					// debugger
					if(vm.currPage<vm.totalPage){
						vm.currPage++;
						vm.getWarningRecordList("up","");
					}
					
				},
				/**
				 * 下拉刷新具体业务实现
				 */
				pulldownRefresh() {
					// debugger
					vm.currPage = 1;
					vm.getWarningRecordList("down","");
				},
			  bu1(id){
				  console.log(id);
				  window.location.href="gdinfo.html?gid="+id;
			  },
			  update(id){
			  	console.log(id);
			  	window.location.href="indexgdadd.html?gid="+id;
			  },
			  receive(id){
			  	var btnArray = ['否', '是'];
					mui.confirm('是否接收该工单？', '接收', btnArray, function(e) 
					{
						if (e.index == 1) 
						{
							var bussMaintainTaskreceive = {'id':id,'status':1}
							mui.ajax(baseUrl+"/buss/bussmaintaintask/update/",{
									data:JSON.stringify(bussMaintainTaskreceive),
									//},
									async: false,
									contentType: "application/json",
									type:'post',//HTTP请求类型
									//headers:{'Content-Type':'application/json'},	              
									success:function(data){
										if(data.code == 0){
											mui.toast('接收成功', {
												duration: 'long',
												type: 'div'
											})
											window.location.href=window.location.href;
										}else{
											mui.toast('接收失败', {
												duration: 'long',
												type: 'div'
											})
										}
										
									},error: function(xhr, type, errorThrown) {
										//异常处理；
										mui.toast('添加失败', {
											duration: 'long',
											type: 'div'
										})
									}
							})
							
							
						} 
						else 
						{
							//info.innerText = 'MUI没有得到你的认可，继续加油'
						}
					})
			  },
			  del(id){
				var btnArray = ['否', '是'];
			 		mui.confirm('是否删除该工单？', '删除', btnArray, function(e) 
			 		{
			 			if (e.index == 1) 
			 			{   
			 				var bussMaintainTaskreceive = [id]
			 				mui.ajax(baseUrl+"/buss/bussmaintaintask/delete",{
			 						data:JSON.stringify(bussMaintainTaskreceive),
			 						//},
			 						async: false,
			 						contentType: "application/json",
			 						type:'post',//HTTP请求类型
			 						//headers:{'Content-Type':'application/json'},	              
			 						success:function(data){
			 							if(data.code == 0){
			 								mui.toast('删除成功', {
			 									duration: 'long',
			 									type: 'div'
			 								})
			 								window.location.href=window.location.href;
			 							}else{
			 								mui.toast('删除失败', {
			 									duration: 'long',
			 									type: 'div'
			 								})
			 							}
			 							
			 						},error: function(xhr, type, errorThrown) {
			 							//异常处理；
			 							mui.toast('添加失败', {
			 								duration: 'long',
			 								type: 'div'
			 							})
			 						}
			 				})
			 				
			 				
			 			} 
			 			else 
			 			{
			 				//info.innerText = 'MUI没有得到你的认可，继续加油'
			 			}
			 		})
			  },
			  fk(id){
				 window.location.href="indexgdfk.html?gid="+id
			  }
				
			},
			mounted() {
				mui.init({
					swipeBack: false,
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							style:'circle',
							callback: this.pulldownRefresh
						},
						up: {
							auto:true,
							contentrefresh: '正在加载...',
							callback: this.pullupRefresh
						}
					}
				});
			}
		});
		
		</script>
		
		

	</body>

</html>